package com.jmu.lambda;

import java.util.Arrays;
import java.util.Date;

public class TestStaff {

    private static void printName(Staff[] staffs) {
        for (Staff s:staffs
             ) {
            System.out.println(s.getName());
        }
    }

    private static void printSalary(Staff[] staffs) {
        for (Staff staff:staffs
             ) {
            System.out.println(staff.getSalary());
        }
    }



    public static void main(String[] args) {
        //添加若干个Staff, Teacher, SecurityGuard, Dean实例
        Staff staff = new Staff("A","AXXX",18,"boy",1500,new Date(2016,11,12));
        Staff staff1 = new Staff("E", "EXXX", 21, "woman", 2300, new Date(2017,1,8));
        Staff teacher = new Teacher("G","BXXX",32,"man",4500,new Date(1994,6,8),"Computer","soft",1200);
        Staff securityGuard = new SecurityGuard("C","CXXX",26,"man",2000,new Date(2008,10,1),"kill",1500);
        Staff dean = new Dean("D","DXXX",52,"man",6000,new Date(2015,9,8),3000);

        Staff[] employee = {staff1, teacher, securityGuard, dean, staff};



        System.out.println("打印姓名排序:");
        Arrays.sort(employee, ((o1, o2) -> o1.getName().compareTo(o2.getName())));
        printName(employee);

        System.out.println("打印年龄排序:");
        Arrays.sort(employee, ((o1, o2) -> o1.getAge() - o2.getAge()));
        for (Staff s:employee
             ) {
            System.out.println(s.getAge());
        }

        System.out.println("打印复合排序(优先年龄，其次薪水）：");
        Arrays.sort(employee, ((o1, o2) -> {
            if (o1.getAge() > o2.getAge())
                return 1;
            else if (o1.getAge() < o2.getAge())
                return -1;
            else if (o1.getSalary() > o2.getSalary())
                return 1;
            else if (o1.getSalary() < o2.getSalary())
                return -1;
            return 0;
        }));
        for (Staff s : employee) {
            System.out.println(s.getAge() + " " + s.getSalary());
        }

    }

}
